package com.hexinfo.dmpro.data.transfer.common.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.data.transfer.common.model.DataTransferTableFilter;
import com.hexinfo.dmpro.data.transfer.common.service.impl.DataTransferTableFilterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/api/data/transfer/table/filter")
@Api(value = "dataTransferTableFilter", tags = "数据同步过滤表管理")
public class DataTransferTableFilterController {

    private final DataTransferTableFilterService dataTransferTableFilterService;

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public ResponseEntity<Object> getDesensitizeFieldListPage(Page page, DataTransferTableFilter dataTransferTableFilter) {
        return ResponseEntity.ok(dataTransferTableFilterService.queryList(page, dataTransferTableFilter));
    }

    @ApiOperation(value = "新增数据同步过滤表", notes = "新增数据同步过滤表")
    @PostMapping
    public ResponseEntity<Object> save(@RequestBody DataTransferTableFilter dataTransferTableFilter) {
        return new ResponseEntity<>(dataTransferTableFilterService.create(dataTransferTableFilter), HttpStatus.OK);
    }

    @ApiOperation(value = "修改数据同步过滤表", notes = "修改数据同步过滤表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody DataTransferTableFilter dataTransferTableFilter) {
        return ResponseEntity.ok(dataTransferTableFilterService.updateById(dataTransferTableFilter));
    }

    @ApiOperation(value = "通过id删除数据同步过滤表", notes = "通过id删除数据同步过滤表")
    @DeleteMapping("/{ids}")
    public ResponseEntity<Object> removeByIds(@PathVariable("ids") @NotNull List<String> ids) {
        return ResponseEntity.ok(dataTransferTableFilterService.removeByIds(ids));
    }

}
